package com.woniu.controller;

import com.nimbusds.jose.JOSEException;
import com.woniu.entity.Employee;
import com.woniu.service.EmployeeService;
import com.woniu.util.ResponseData;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/employee")
public class EmployeeController {

    @Resource   // @Resource 既可以按照名称注入，也可以在找不到名称匹配的 bean 时按照类型注入
    private EmployeeService employeeService;


    /**
    * 登录接口
    * */
    @PostMapping("/login")
    public ResponseData<?> login(@RequestBody Employee employee) {
        try {
            return employeeService.login(employee);
        } catch (JOSEException e) {
            throw new RuntimeException(e);
        }
    }

    @GetMapping("/getSelfInfo")
    public ResponseData<?> getSelfInfo() {
        return employeeService.getSelfInfo();
    }

    @PostMapping("/updateEmployee")
    public ResponseData<?> updateEmployee(@RequestBody Employee employee) {
        return employeeService.updateEmployee(employee);
    }
}
